Script CHTTPServer
(name, config)

String Name = name;
HTTPServer@QHTTP HTTP;

Constructor(config);

Script Constructor
(config)
AppLog("In contructor of CHTTPServer, ", Name);

String localIP = 0, localport = 0;
String filename, timeformat = "%Z ", handler = "QHTTP_Handler";
U4 timeoption = 3;
I4 ret;

String key;
U0 i;
Reference p;

StrAssign(filename, "Log/", Name, "_%Y%M%D.txt");

foreach (p, config, i, key)
{
	switch (key)
	{
	case "Local port"
		localport = p;
		break;

	case "Local IP"
		localIP = p;
		break;

	case "Time format"
		timeformat = p;
		break;

	case "Time option"
		timeoption = p;
		break;

	case "Handler"
		handler = p;
		break;
	}
}

ConfigureHelper("Name", Name);				//Name should be object name used in GCreateEx2 for the HTTPServer
ConfigureHelper("LocalIP", localIP);
ConfigureHelper("LocalPort", localport);
ConfigureHelper("LogFileName", filename);
ConfigureHelper("TimeFormat", timeformat);
ConfigureHelper("Handler", handler);

StartHttpServer@QHTTP(HTTP, ret);
if (ret)
{
	AppLog("Failed to start CHTTPServer ", Name);
}
else
{
	AppLog("CHTTPServer ", Name, " started");
}
EndScript

Script ConfigureHelper
(key, value)

I4 ret;

ConfigureHttpServer@QHTTP(HTTP, key, value, ret);
if (ret)
{
	AppLog("Failed to set ", Name, " property, ", key, ", ", value);
}
EndScript

EndScript

